package com.qeegoo.b2bautozityp.moudle.goods.view;

//┏┓　　　┏┓ 
//┏┛┻━━━┛┻┓ 
//┃　　　　　　　┃ 　 
//┃　　　━　　　┃ 
//┃　┳┛　┗┳　┃ 
//┃　　　　　　　┃ 
//┃　　　┻　　　┃ 
//┃　　　　　　　┃ 
//┗━┓　　　┏━┛ 
//┃　　　┃  神兽保佑　　　　　　　　 
//┃　　　┃  代码无BUG！ 
//┃　　　┗━━━┓ 
//┃　　　　　　　┣┓ 
//┃　　　　　　　┏┛ 
//┗┓┓┏━┳┓┏┛ 
// ┃┫┫　┃┫┫ 
// ┗┻┛　┗┻┛

import android.support.v4.view.ViewPager;
import android.view.View;

import com.kelin.mvvmlight.messenger.Messenger;
import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.adapter.OrderFragmentAdapter;
import com.qeegoo.b2bautozityp.constant.Constants;
import com.qeegoo.b2bautozityp.databinding.ActivityGoodsManagerBinding;
import com.qeegoo.b2bautozityp.injector.component.DaggerGoodsManagerComponent;
import com.qeegoo.b2bautozityp.moudle.base.BaseActivity;
import com.qeegoo.b2bautozityp.moudle.base.LazyLoadFragment;
import com.qeegoo.b2bautozityp.moudle.goods.viewmodel.GoodsManagerViewModel;
import com.qeegoo.b2bautozityp.widget.TabBarUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by lk on 2017/9/20.
 */

public class GoodsManagerActivity extends BaseActivity<ActivityGoodsManagerBinding> {
    private String[] titles = {"已上架", "已下架", "已售罄"};
    private List<LazyLoadFragment> fragments = new ArrayList<>();


    @Inject
    GoodsManagerViewModel viewModel;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_goods_manager;
    }

    @Override
    protected void initInjector() {
        DaggerGoodsManagerComponent.builder().appComponent(getAppComponent()).activityComponent(getActivityComponent()).build().inject(this);
    }

    @Override
    protected void initViews() {
        initFragment();
        mBinding.tabLayout.addTab(mBinding.tabLayout.newTab().setText(titles[0]), true);
        mBinding.tabLayout.addTab(mBinding.tabLayout.newTab().setText(titles[1]));
        mBinding.tabLayout.addTab(mBinding.tabLayout.newTab().setText(titles[2]));
        OrderFragmentAdapter mFragmentAdapteradapter =
                new OrderFragmentAdapter(getSupportFragmentManager(), fragments, titles);
        mBinding.viewpager.setAdapter(mFragmentAdapteradapter);
        mBinding.viewpager.setOffscreenPageLimit(3);
        mBinding.tabLayout.setupWithViewPager(mBinding.viewpager);
        TabBarUtils.setIndicator(mBinding.tabLayout, 30, 30);
        mBinding.setViewModel(viewModel);
        mBinding.viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                viewModel.visible.set(position == 0 ? View.VISIBLE : View.GONE);
                viewModel.leftText.set("批量管理");
                GoodsManagerViewModel.GoodsPageData data = new GoodsManagerViewModel.GoodsPageData(3, false);
                Messenger.getDefault().send(data, GoodsManagerFragment.class.getSimpleName());//通知 刷新recycler
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initFragment() {
        fragments.add(GoodsManagerFragment.newInstance(Constants.OrderType_1));
        fragments.add(GoodsManagerFragment.newInstance(Constants.OrderType_2));
        fragments.add(GoodsManagerFragment.newInstance(Constants.OrderType_3));
    }


}
